package com.zgs.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;

//ConstraintValidator<A extends Annotation, T>  A 指定校验注解    T 校验什么类型的属性
public class ListValueConstraintValidator   implements ConstraintValidator<ListValue, Integer> {
    private Set<Integer> set =new HashSet<Integer>();
    //获取注解详细信息
    @Override
    public void initialize(ListValue constraintAnnotation) {
        int[] value = constraintAnnotation.value();
        for(int va:value){
            set.add(va);
        }
    }
    //value 需要校验的值
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
